package com.saas.demo.comman;

/**
 * @program: demo
 * @description: 本地线程共享变量
 * @author: guoxh
 * @create: 2019-01-25 15:19
 **/
public class CommonParam {
    private static ThreadLocal<CommonParam> threadLocal = new ThreadLocal<CommonParam>();

    public static CommonParam getInstance() {
        //获取ThreadLocal中当前线程共享变量的值
        CommonParam param = threadLocal.get();
        if (param == null) {
            param = new CommonParam();
            //设置ThreadLocal中当前线程共享变量的值
            threadLocal.set(param);
        }
        return param;
    }

    //移除ThreadLocal中当前线程共享变量的值
    public static void remove() {
        threadLocal.remove();
    }

    //线程本地变量
    private int tenantId = -1;
    private long startTime;

    public int getTenantId() {
        return tenantId;
    }

    public void setTenantId(int tenantId) {
        this.tenantId = tenantId;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }
}
